﻿//https://leetcode.cn/problems/fruit-into-baskets/
class Solution
{
public:
	int totalFruit(vector<int>& f)
	{
		int hash[100001] = { 0 }; // 统计窗⼝内出现了多少种⽔果
		int ret = 0;
		for (int left = 0, right = 0, kinds = 0; right < f.size(); right++)
		{
			if (hash[f[right]] == 0) kinds++; // 维护⽔果的种类
			hash[f[right]]++; // 进窗⼝
			while (kinds > 2) // 判断
			{
				// 出窗⼝
				hash[f[left]]--;
				if (hash[f[left]] == 0) kinds--;
				left++;
			}
			ret = max(ret, right - left + 1);
		}
		return ret;
	}
};